package com.cocoiko.customview;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.cocoiko.UserCocoiko;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context context;

	public MapItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));

	}

	public MapItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		this.context = context;
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	public void addOverlay(OverlayItem overlay) {

		mOverlays.add(overlay);
		populate();
	}

	public void removeItem(int index) {
		if (index < size()) {
			mOverlays.remove(index);
			populate();
		}
	}

	public void clear() {
		mOverlays.clear();
		populate();
	}

	@Override
	protected boolean onTap(int index) {

		OverlayItem item = mOverlays.get(index);
		Intent intent = new Intent(context, UserCocoiko.class);
		intent.putExtra("user_name", item.getTitle());
		intent.putExtra("user_email", item.getSnippet());
		context.startActivity(intent);

		return true;
	}
}
